package com.jack.leetcode.eachproblem_2020;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CopyOnWriteArrayList;

public class 数组中的最长山脉 {

    public static int longestMountain(int[] A) {
        if(A == null || A.length < 3){
            return 0;
        }
        int result = 0;
        int n = A.length;
        int[] left = new int[n];
        for(int i = 1;i < n;i++){
            left[i] = A[i] > A[i - 1] ? left[i - 1] + 1 : 0;
        }
        int[] right = new int[n];
        for(int i = n - 2;i >= 0;i--){
            right[i] = A[i] > A[i + 1] ? right[i + 1] + 1 : 0;
        }
        for(int i = 0;i < n;i++){
            if(left[i] > 0 && right[i] > 0){
                result = Math.max(result, left[i] + right[i] + 1);
            }
        }
        return result;
    }

    volatile static int a = 1;
    public static void main(String[] args) {
        int[] a = {2,1,4,7,3,2,5};
        System.out.println(longestMountain(a));

    }
}
